package br.ufrn.opencopi.graph;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import br.cnpq.webflowah.beans.Operacao;
import br.cnpq.webflowah.beans.WorkflowSemantico;

public class Graph {

	private WorkflowSemantico workflow;

	private List<GraphPath> paths;

	private List<Vertex> vertexs;

	public Graph(WorkflowSemantico workflow){
		paths = new ArrayList<GraphPath>();
		vertexs = new ArrayList<Vertex>();
		this.workflow = workflow;
	}

	/*public Graph(List<GraphPath> paths, WorkflowSemantico workflow) {
		super();
		this.paths = paths;
		this.workflow = workflow;
	}*/

	public List<GraphPath> getPaths() {
		return paths;
	}

	public void setPaths(List<GraphPath> paths) {
		this.paths = paths;
	}

	public WorkflowSemantico getWorkflow() {
		return workflow;
	}

	public void insertNewPath(GraphPath path){
		paths.add(path);
	}

	public void removePath(GraphPath path){
		paths.remove(path);
	}

	public void addVertex(Vertex vertex){
		if(!vertexs.contains(vertex))
			vertexs.add(vertex);
	}

	public int getVertexByURI(String uri){
		Vertex v;
		for(int i = 1; i < vertexs.size(); i++){
			v = vertexs.get(i);
			if(v instanceof ServiceVertex){
				if(((ServiceVertex)v).getUri().equals(uri)){
					return v.id;
				}
			}
		}
		return -1;
	}

	public Vertex getVertexById(int id){
		Vertex v;
		for(int i = 2; i < vertexs.size(); i++){
			v = vertexs.get(i);
			if(v instanceof ServiceVertex){
				if(((ServiceVertex)v).getId() == id){
					return v;
				}
			}
		}
		return null;
	}

}
